package run;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import misc.Properties;

public class Loader {

	private Properties properties = null;

	public Loader() {
		this.properties = loadProperties();
	}
	
	public Loader(Properties properties){
		this.properties = properties;
	}
	
	public void saveProperties(){
		if (new File("properties.val").exists()){
			new File("properties.val").delete();
		}
		try {
			ObjectOutputStream out = new ObjectOutputStream(
					new BufferedOutputStream(
							new FileOutputStream("properties.val")));
			out.writeObject(properties);
			out.close();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
	private Properties loadProperties() {
		if (new File("properties.val").exists()){
			try {
				ObjectInputStream in = new ObjectInputStream(
						new BufferedInputStream(
								new FileInputStream("properties.val")));
				return(Properties)in.readObject();
				
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
		return new Properties();
	}
	
	
}
